package com.bluegalaxy.nhb.core.helpers;



import com.bluegalaxy.nhb.domain.vo.sql.SqlInfo;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;

import java.util.Arrays;

/**
 * 打印SqlInfo信息的工具类.
 * @author
 */
public class SqlInfoPrinter {

//    private static Log log = LogFactory.getLog(SqlInfoPrinter.class);

    private static final String PRINT_START = "------------------------------------------------------------ "
            + "Zealot生成的SQL信息 ---------------------------------------------------------";

    private static final String PRINT_END = "---------------------------------------------------------------"
            + "--------------------------------------------------------------------------";

    /** 换行符. */
    private static final String LINE_BREAK = "\n";

    /**
     * 私有构造方法.
     */
    private SqlInfoPrinter() {
        super();
    }

    /**
     * 获取新的实例.
     * @return PrintSqlInfoHelper实例
     */
    public static SqlInfoPrinter newInstance() {
        return new SqlInfoPrinter();
    }

    /**
     * 打印SqlInfo的日志信息.
     * @param nameSpace XML命名空间
     * @param zealotId XML中的zealotId
     * @param sqlInfo 要打印的SqlInfo对象
     * @param hasXml 是否包含xml的打印信息
     */
    public void printZealotSqlInfo(SqlInfo sqlInfo, boolean hasXml, String nameSpace, String zealotId) {
        // 如果可以配置的打印SQL信息，且日志级别是info级别,则打印SQL信息.
//        if (NormalConfig.getInstance().isPrintSqlInfo()) {
            StringBuilder sb = new StringBuilder(LINE_BREAK);
            sb.append(PRINT_START).append(LINE_BREAK);


            sb.append("-------- SQL: ").append(sqlInfo.getSql()).append(LINE_BREAK)
                    .append("----- Params: ").append(Arrays.toString(sqlInfo.getParamsArr())).append(LINE_BREAK);
            sb.append(PRINT_END).append(LINE_BREAK);
//            log.info(sb.toString());
        }
//    }

}